function K_mod_reg = func_Km_R_mod(zeta, m, CONSTS, p_m_vec, n_beg_sum, depend_from_zeta, plot_data)

    a = CONSTS.a;
    k0 = CONSTS.k0;
    c = CONSTS.c;
    d = CONSTS.d;
    eps = CONSTS.eps;
    eta = CONSTS.eta;
    
    Z0 = 4*pi/c;
    
    %p_m_vec = func_p_m(m, CONSTS, span, false);
    %n_beg_sum = n_begining_sum(CONSTS, p_m_vec);
    coef_m_mat = func_coef_m_of_eigenmodes(m, CONSTS, p_m_vec);
    
    if(depend_from_zeta)
        
        diff = zeros(size(zeta), 1);

        for i = n_beg_sum:size(p_m_vec, 1)

            n = i;
            p_n = p_m_vec(i);
            coef_n = coef_m_mat(:, i);
            norm = func_norm(m, CONSTS, coef_n, p_n);
            [~, ~, ~, ~, Ephi, ~] = func_HE_outside(1, m, CONSTS, coef_n, p_n); %func_HE_inside(a, m, CONSTS, coef_n, p_n);

            K_mn_num = zeros(size(zeta), 1);
            K_mn_an = zeros(size(zeta), 1);
            diff_n = zeros(size(zeta), 1);
            for ii = 1:size(zeta,1)
                zeta_i = zeta(ii);
                if(norm==0)
                    K_mn_num(ii) = 0;
                else
                    K_mn_num(ii) = (2*pi*a/norm)*(Ephi^2)*exp(-1i*k0*p_n*abs(zeta_i));
                    K_mn_an(ii) = -Z0*((2*m^2*k0)/(pi*(k0*a)^2*sqrt(eps*abs(eta))))*((exp(-1i*k0*p_n*abs(zeta_i)))/(2*n+m+1/2));
                end
                diff_n(ii) = K_mn_num(ii) - K_mn_an(ii);
            end
            
            diff_n(isnan(diff_n))=0;

            diff = diff + diff_n;
        end
        
        K_mod_reg_dif = diff;
            
        if(plot_data)
            figure; plot(zeta./d, real(K_mod_reg_dif), 'b-', zeta./d, imag(K_mod_reg_dif), 'r-');
            title('K_{m, mod} regular part from N to inf'); legend('Re(K_m reg)', 'Im(K_m reg)');
            xlabel('\zeta/d');
        end
        
        K_mod_reg_begin = zeros(size(zeta), 1);
                
        for l = 1:n_beg_sum-1
            
            p_n_beg = p_m_vec(l);
            coef_n_beg = coef_m_mat(:, l);
            norm_beg = func_norm(m, CONSTS, coef_n_beg, p_n_beg);
            [~, ~, ~, ~, Ephi_beg, ~] = func_HE_outside(1, m, CONSTS, coef_n_beg, p_n_beg); %func_HE_inside(a, m, CONSTS, coef_n, p_n);

            K_mn_num_beg = zeros(size(zeta), 1);
            for ll = 1:size(zeta,1)
                zeta_l = zeta(ll);
                if(norm_beg==0)
                    K_mn_num_beg(ll) = 0;
                else
                    K_mn_num_beg(ll) = (2*pi*a/norm_beg)*(Ephi_beg^2)*exp(-1i*k0*p_n_beg*abs(zeta_l));
                end
            end

            K_mod_reg_begin = K_mod_reg_begin + K_mn_num_beg;

        end
        
        K_mod_reg = K_mod_reg_dif + K_mod_reg_begin;
        
        if(plot_data)
            figure; plot(zeta./d, real(K_mod_reg), 'b-', zeta./d, imag(K_mod_reg), 'r-');
            title('K_{m, mod} regular part n = from 0 to inf'); legend('Re(K_m reg)', 'Im(K_m reg)');
            xlabel('\zeta/d');
        end


    else
        
        diff = zeros((size(p_m_vec, 1)-n_beg_sum+1), 1);
        K_mn_num = zeros((size(p_m_vec, 1)-n_beg_sum+1), 1);
        K_mn_an = zeros((size(p_m_vec, 1)-n_beg_sum+1), 1);
        
        for j = n_beg_sum:size(p_m_vec, 1)
            n = j;
            p_n = p_m_vec(j);
            coef_n = coef_m_mat(:, j);
            norm = func_norm(m, CONSTS, coef_n, p_n);
            [~, ~, ~, ~, Ephi, ~] = func_HE_outside(1, m, CONSTS, coef_n, p_n);
            if(norm==0)
                K_mn_num(j) = 0;
                K_mn_an(j) = 0;
            else
                K_mn_num(j) = (2*pi*a/norm)*(Ephi^2)*exp(-1i*k0*p_n*abs(zeta));
                K_mn_an(j) = -Z0*((2*m^2*k0)/(pi*(k0*a)^2*sqrt(eps*abs(eta))))*((exp(-1i*k0*p_n*abs(zeta)))/(2*n+m+1/2));
            end
            diff(j) = K_mn_num(j) - K_mn_an(j);
        end
        
            K_mod_reg_dif = diff;
            K_mod_reg = K_mod_reg_dif;
            
            if(plot_data)
                n_vec = (1:size(p_m_vec, 1))';
                figure; plot(n_vec, real(K_mod_reg_dif), 'b-', n_vec, imag(K_mod_reg_dif), 'r-');
                title('K_{m, mod} regular part from N to inf'); legend('Re(K_m reg)', 'Im(K_m reg)');
                xlabel('n');
            end
    end
    
end

